using System;
using System.Collections;
using System.Collections.Generic;

namespace foundation
{
    internal class AMF3ObjectVectorWriter : IAMFWriter
    {
        #region IAMFWriter Members

        public bool IsPrimitive
        {
            get { return false; }
        }

        public void WriteData(AMFWriter writer, object data)
        {
            IList list = data as IList;
            if (list != null)
            {
                writer.WriteByte(AMF3TypeCode.ObjectVector);
                writer.WriteAMF3ObjectVector(list);
            }
        }

        #endregion
    }




    class AMF3VectorWriter : IAMFWriter
    {
        public AMF3VectorWriter()
        {
        }
        #region IAMFWriter Members

        public bool IsPrimitive { get { return false; } }

        public void WriteData(AMFWriter writer, object data)
        {

            // Type type = data.GetType().GenericTypeArguments[0];

            var tdata = data as Array;

            if (null != tdata)
            {
                writer.WriteByte(AMF3TypeCode.Array);
                writer.WriteAMF3Array(tdata);
                return;
            }

            var ldata = data as IList;
            if (null != ldata)
            {
                writer.WriteByte(AMF3TypeCode.ObjectVector);
                writer.WriteAMF3ObjectVector(ldata);
                return;
            }

            // else
            // {

            // }


            // return;

            // if (type == typeof(object))
            // {

            // }

            // if (type == typeof(int) || type == typeof(short))
            // {
            //     writer.WriteByte(AMF3TypeCode.IntVector);

            //     IList rawData = (IList)data;
            //     List<int> list = new List<int>(rawData.Count);
            //     foreach (int item in rawData)
            //     {
            //         list.Add(item);
            //     }

            //     writer.WriteAMF3IntVector(list, data is Array);
            //     return;
            // }

            // if (type == typeof(uint) || type == typeof(ushort))
            // {
            //     writer.WriteByte(AMF3TypeCode.UIntVector);

            //     IList rawData = (IList)data;
            //     List<uint> list = new List<uint>(rawData.Count);
            //     foreach (uint item in rawData)
            //     {
            //         list.Add(item);
            //     }
            //     writer.WriteAMF3UIntVector(list, data is Array);
            //     return;
            // }

            // if (type == typeof(float))
            // {
            //     writer.WriteByte(AMF3TypeCode.NumberVector);
            //     IList rawData = (IList)data;
            //     List<double> list = new List<double>(rawData.Count);
            //     foreach (float item in rawData)
            //     {
            //         list.Add(Convert.ToDouble(item));
            //     }
            //     writer.WriteAMF3DoubleVector(list, data is Array);
            //     return;
            // }

            // if (type == typeof(double))
            // {
            //     writer.WriteByte(AMF3TypeCode.NumberVector);
            //     IList rawData = (IList)data;
            //     List<double> list = new List<double>(rawData.Count);
            //     foreach (double item in rawData)
            //     {
            //         list.Add(item);
            //     }
            //     writer.WriteAMF3DoubleVector(list, data is Array);
            //     return;
            // }


            // IList tlist = data as IList;
            // if (tlist != null)
            // {
            //     writer.WriteByte(AMF3TypeCode.ObjectVector);
            //     writer.WriteAMF3ObjectVector(tlist);
            // }
            // else
            // {
            //     if (data is IList)
            //     {
            //         var rawData = (IList)data;
            //         object[] arr = new object[rawData.Count];
            //         for (int i = 0; i < rawData.Count; i++)
            //         {
            //             arr[i] = rawData[i];
            //         }
            //         data = arr;
            //     }

            //     writer.WriteByte(AMF3TypeCode.Array);
            //     writer.WriteAMF3Array(data as Array);
            // }



            // writer.WriteByte(AMF3TypeCode.ObjectVector);
            // writer.WriteAMF3ObjectVector(data as IList);
        }

        #endregion
    }
}
